package cn.kooki.app.duobao.ui.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.R;

/**
 * Created by xiong on 2015/12/13.
 */
public class MoneyPicker extends FrameLayout implements View.OnClickListener {
    @Bind(R.id.money0)
    TextView money0;
    @Bind(R.id.money1)
    TextView money1;
    @Bind(R.id.money2)
    TextView money2;
    @Bind(R.id.money3)
    TextView money3;
    @Bind(R.id.money4)
    TextView money4;
    @Bind(R.id.input)
    EditText input;


    private int selected_Tag = 0;

    public MoneyPicker(Context context) {
        this(context, null);
    }

    public MoneyPicker(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MoneyPicker(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }


    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public MoneyPicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }


    public String getselectPrice() {
        switch (selected_Tag) {
            case 0:
                return money0.getText().toString();
            case 1:
                return money1.getText().toString();
            case 2:
                return money2.getText().toString();
            case 3:
                return money3.getText().toString();
            case 4:
                return money4.getText().toString();
            case 5:
                return input.getText().toString();
            default:
                return "";
        }
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.layout_moneypicker, this, true);
        ButterKnife.bind(this);
        money0.setText("20");
        money0.setTag(0);
        money1.setText("50");
        money1.setTag(1);
        money2.setText("100");
        money2.setTag(2);
        money3.setText("200");
        money3.setTag(3);
        money4.setText("500");
        money4.setTag(4);
        input.setTag(5);
        money0.setOnClickListener(this);
        money1.setOnClickListener(this);
        money2.setOnClickListener(this);
        money3.setOnClickListener(this);
        money4.setOnClickListener(this);
        input.setOnClickListener(this);
        money0.setSelected(true);
    }

    @Override
    public void onClick(View v) {
        changeselect(v);
    }

    private void changeselect(View v) {
        money0.setSelected(false);
        money1.setSelected(false);
        money2.setSelected(false);
        money3.setSelected(false);
        money4.setSelected(false);
        input.setSelected(false);
        v.setSelected(true);
        selected_Tag = (int) v.getTag();
    }
}
